﻿@model IEnumerable<CNRegex.Entity.RegexTutorial>
@{
	ViewBag.Title = "教程管理";
	Layout = "~/Views/Shared/_LayoutBack.cshtml";
}

<script type="text/javascript">
	var dialog;
	function showCreate() {
		dialog = $("#dialog").dialog();
		$("#tutorialName").val("");
		$("#type").val("");
		$("#description").val("");
		$("#author").val("");
		$("#hiddenID").val("");
	}
	function closeDialog() {
		$("#dialog").dialog("close");
	}
	function save() {
		var name = $("#tutorialName").val();
		var type = $("#type").val();
		var description = $("#description").val();
		var author = $("#author").val();
		var id = $("#hiddenID").val();
		$.ajax({
			type: "POST",
			url: "/AdminRegexTutorial/Save",
			data: "name=" + name + "&type=" + type + "&description=" + description + (id == "" ? "" : "&id=" + id + "")+"&author="+author,
			success: function (msg) {
				window.location = window.location;
			}
		});
	}

	function deleteItem(id) {
		if (!confirm("确定要删除?"))
			return;
		$.ajax({
			type: "POST",
			url: "/AdminRegexTutorial/Delete",
			data: "id=" + id,
			success: function (msg) {
				window.location = window.location;
			}
		});
	}

	function edit(id, name, type, description,author) {
		$("#tutorialName").val(name);
		$("#type").val(type);
		$("#description").val(description);
		$("#author").val(author);
		$("#hiddenID").val(id);
		$("#dialog").dialog();
	}
</script>
<div class="stateBar">
	<img src="/images/dot.gif" alt="position" />
	您现在的位置 → <span class="bfont">@ViewBag.Title</span>
</div>
<div class="toolBar">
	<span style="float: right; margin-right: 5px;">
		<a href="javascript:showCreate();"
		style="text-decoration: none;">
			<img src="/images/add.gif" alt="add" />
			<span style="position: relative; top: -3px;">新增</span> 
		</a>
	</span>
</div>
<table class="box-table-a">
	<colgroup>
		<col width="15%" />
		<col />
		<col />
	</colgroup>
	<tr>
		<th scope="col">
		</th>
		<th scope="col">
			教程名称
		</th>
		<th scope="col">
			类型
		</th>
		<th scope="col">
			描述
		</th>
		<th scope="col">
			创建日期
		</th>
	</tr>
	@foreach (var item in Model)
 {
		<tr>
			<td align="center">
				<a href="javascript:edit('@item.ID','@item.Name','@item.type','@item.Description','@item.Author')">编辑</a> |
				<a href="javascript:deleteItem('@item.ID')">删除</a>
				<a href="/AdminRegexTutorialCatalog/index/@item.ID">进入目录</a>
			</td>
			<td>
				@item.Name
			</td>
			<td>
				@(((CNRegex.Enum.EnumTutorialType)item.type).ToString())
			</td>
			<td>
				@item.Description
			</td>
			<td>
				@item.CreateDate
			</td>
		</tr>
 }
</table>
<div id="dialog" title="创建教程" style="display: none;">
	<p>
		<span>名称:</span>
		<input name="name" id="tutorialName" />
	</p>
	<p>
		<span>类型:</span>
		@(Html.DropDownList("type",CNRegex.Web.Utility.ConvertEnumToSelectList.ComposeSelectListFromEnum<CNRegex.Enum.EnumTutorialType>()))
		<input type="hidden" id="hiddenID" name="id" />
	</p>
	<p>
		<span>描述:</span>
		<input name="description" id="description" />
	</p>
	<p>
		<span>作者:</span>
		<input name="author" id="author" />
	</p>
	<div style="text-align: center; margin-top: 4px;">
		<input type="button" value="确定" onclick="save();" />
		<input type="button" value="取消" onclick="closeDialog();" />
	</div>
</div>
